package com.lesserpand.rabbitmq.threadpool.thread;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * @author pand
 * @version 0.0.1
 * @package com.topinfo.locationservice.utils.thread
 * @description 自定义线程池策略，没有做处理。即线程池满了之后的处理策略
 * @date Created in 2019/4/1 15:00
 * @company
 * @copyright Copyright (c) 2017
 * @modified By
 */
@Component
public class SyncRejectedExecutionHandler implements RejectedExecutionHandler {

    private static final Logger LOGGER = LoggerFactory.getLogger(SyncRejectedExecutionHandler.class);

    @Override
    public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {

        LOGGER.info("线程池满了,队列扩容");
        if (!executor.isShutdown()) {
            try {
                executor.getQueue().put(r);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

    }
}
